package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.WorkshopWarehouseListPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.WorkshopWarehouseListView
import com.weetop.cfw.bean.*
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.home_page.activity.PublishActivity
import com.weetop.cfw.home_page.activity.WorkshopWarehouseListActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class WorkshopWarehouseListPresenterImp(var workshopWarehouseListView: WorkshopWarehouseListView? = null): WorkshopWarehouseListPresenter {

    /**
     * 获取分类的数据
     */
    override fun getKindData(workshopWarehouseListActivity: WorkshopWarehouseListActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().kind(),workshopWarehouseListActivity,object:RxJavaCallBack<KindBean>(){
            override fun onSuccess(t: KindBean?) {
                workshopWarehouseListView?.kindDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取面积的数据
     */
    override fun getAreaData(workshopWarehouseListActivity: WorkshopWarehouseListActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().generalCodeTable(1100),workshopWarehouseListActivity,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                workshopWarehouseListView?.areaDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取区域的数据
     */
    override fun getQuYuData(workshopWarehouseListActivity: WorkshopWarehouseListActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().quYu(Constants.cityId),workshopWarehouseListActivity,
            object : RxJavaCallBack<SiteBean>() {
                override fun onSuccess(t: SiteBean?) {
                    workshopWarehouseListView?.quYuGetSuccess(t)
                }
            })
    }

    /**
     * 获取价格过滤的数据
     */
    override fun getPriceData(workshopWarehouseListActivity:WorkshopWarehouseListActivity,punit:Int) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().generalCodeTable(punit),workshopWarehouseListActivity,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                workshopWarehouseListView?.priceFilterDataGetSuccess(t)
            }
        })
    }

    /**
     * 根据站点ID获取出租价格单位
     */
     fun getPriceUnitBySiteId(workshopWarehouseListActivity: WorkshopWarehouseListActivity, siteId: Int) {
        //workshopWarehouseListActivity.showLoadingDialog(workshopWarehouseListActivity,"正在获取价格单位...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getPriceUnitBtSite(siteId),workshopWarehouseListActivity,object:RxJavaCallBack<PriceUnitBean>(){
            override fun onSuccess(t: PriceUnitBean?) {
                workshopWarehouseListView?.getPriceUnitSuccess(t?.punit)
            }
        })
    }

    /**
     * 获取行业过滤的数据
     */
    override fun getIndustryData(workshopWarehouseListActivity: WorkshopWarehouseListActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().generalCodeTable(1700),workshopWarehouseListActivity,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                workshopWarehouseListView?.industryFilterDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取来源过滤的数据
     */
    override fun getSourceData(workshopWarehouseListActivity: WorkshopWarehouseListActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().generalCodeTable(1800),workshopWarehouseListActivity,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                workshopWarehouseListView?.sourceFilterDataGetSuccess(t)
            }
        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        workshopWarehouseListView = baseView as? WorkshopWarehouseListView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       workshopWarehouseListView = null
    }
}